﻿@{
    Style.Require("NineSeas.Common");
    Style.Require("NineSeas.Authors");
    
    var pagingParameters = new RouteValueDictionary();
    pagingParameters.Add("pageSize", Model.Paging.PageSize);

    if (!String.IsNullOrEmpty(Model.Search.Expression))
    {
        pagingParameters.Add("Expression", Model.Search.Expression);
    }

    if (!String.IsNullOrEmpty(Model.Search.OrderBy))
    {
        pagingParameters.Add("OrderBy", Model.Search.OrderBy);
    }

    if (!String.IsNullOrEmpty(Model.Search.OrderDirection))
    {
        pagingParameters.Add("OrderDirection", Model.Search.OrderDirection);
    }
}
<div id="nineseas">
    @{var i = 0;}
    @foreach (var author in Model.Authors)
    {        
        var imageUrl = String.IsNullOrWhiteSpace(author.AvatarUrl) ?
            Href("~/Modules/NineSeas/Images/placeholder-photo.png")
            : author.AvatarUrl;
    <div class="author-item @(i % 6 == 5 ? "author-item-last-line": "")">
        <div class="author-item-avatar">
            <a href="@Url.Action("Index", "Author", new {name = author.User.UserName})">
                <img src="@imageUrl" alt="@author.DisplayName"/>
                <div class="author-display-name">
                    @author.DisplayName
                </div>
                <div class="author-item-footer">                    
                    <span class="author-item-likes">@(author.TotalLikes.ToString("#,#;(#,#);0"))</span>
                    <span class="author-item-books">@(author.BookCount.ToString("#,#;(#,#);0"))</span>
                </div>
            </a>
        </div>  
    </div>
        i++;
    }  
    @Display(New.InfiniteScroll(Container: "#nineseas", Item: ".author-item", Pagination: "#paging", Next: "#nextPage"))

    <div style="clear:both"></div>
    <div id="paging">
        @if (Model.Paging.CurrentPage > 0)
        {
            pagingParameters.Add("currentPage", Model.Paging.CurrentPage - 1);
            <a href="@Url.Action("Index", "Authors", pagingParameters)" id="previousPage">&lt; @T("Previous")</a>
        }
        
        @if (Model.Paging.CurrentPage < Model.Paging.TotalPages - 1) {
            if (pagingParameters.ContainsKey("currentPage"))
            {
                pagingParameters["currentPage"] = Model.Paging.CurrentPage + 1;
            }
            else
            {
                pagingParameters.Add("currentPage", Model.Paging.CurrentPage + 1);
            }
            <a href="@Url.Action("Index", "Authors", pagingParameters)" id="nextPage">@T("Next") &gt;</a>
        }
    </div>
    <div id="footer-push"></div>
</div>